#include "sprite.h"

Sprite::Sprite(int x1, int y1, int w1, int h1, bool isV)
{
	setGeometry(x1, y1, w1, h1);
	isVisable = isV;
	setAngD(0);
}
Sprite::~Sprite()
{
}
void Sprite::setGeometry(int x1, int y1, int w1, int h1)
{
	x=x1;y=y1;w=w1;h=h1;
}
void Sprite::setAng(float ang1)
{
	ang = ang1;
	angD = ang*180.0f/PI;
}
void Sprite::setAngD(int angd)
{
    angD = angd;
	ang = angd * (2.0f * PI)/360.0;
}

void Sprite::setColor(QColor c)
{
    color = c;
}

void Sprite::setPosition(int x1, int y1)
{
    x=x1;
	y=y1;
}
/***********************************************************/
BoxSprite::BoxSprite(int x, int y, int w, int h, bool isV):
	Sprite(x, y, w, h, isV)
{
	std::cout<<"constructor of boxsprite"<<std::endl;
}
BoxSprite::~BoxSprite()
{
	std::cout<<"destructor from boxsprite"<<std::endl;
}
void BoxSprite::paint(QPixmap &pix)
{
	QPainter *p = new QPainter();
	p->begin(&pix);
	p->setPen(color);
	p->setBrush(color);
	p->save();
	p->translate(x,y);
	p->rotate(angD);
	if(isVisable)
	{
		p->drawRect(0-w/2, 0-h/2, w, h);
		p->setPen(QColor(255,255,255));
		p->drawLine(0, 0, 0, 0-h/2);
	}
	p->restore();
	p->end();
}

/***********************************************************/
EllipseSprite::EllipseSprite(int x, int y, int w, int h, bool isV):
	Sprite(x, y, w, h, isV)
{
	ang = 0;
	r = w/2;
	std::cout<<"r="<<r<<std::endl;
	std::cout<<"constructor of ellipsesprite"<<std::endl;
}

EllipseSprite::~EllipseSprite()
{
	std::cout<<"destructor from Ellipsesprite"<<std::endl;
}

void EllipseSprite::paint(QPixmap &pix)
{
	QPainter *p = new QPainter();
	p->begin(&pix);
	p->setPen(color);
	p->setBrush(color);
	p->save();
	p->translate(x,y);
	p->rotate(angD);
	if(isVisable)
	{
		p->drawEllipse(0-w/2, 0-h/2, w, h);
		p->setPen(QColor(255,255,255));
		p->drawLine(0, 0, 0, 0-r); 
	}
	p->restore();
	p->end();
}
/***********************************************************/
PolySprite::PolySprite(int x, int y, QPointArray &p, bool isV)
		:Sprite(x, y, 0, 0, isV)
{
		pa = p;
		cout<<"PolySprite constructor"<<endl;
}
PolySprite::~PolySprite()
{
		cout<<"destructor of PolySprite"<<endl;
}
void PolySprite::paint(QPixmap &pix)
{
	QPainter *p = new QPainter();
	p->begin(&pix);
	p->setPen(color);
	p->setBrush(color);
	p->save();
	p->translate(x,y);
	p->rotate(angD);
	if(isVisable)
	{
		p->drawPolygon(pa);
		p->setPen(QColor(255,255,255));
		p->drawLine(0, 0, pa[0].x(), pa[0].y());
	}
	p->restore();
	p->end();
}
/***********************************************************/

